package com.example.zhangwei.service;

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

public class MyBindService extends Service{
	
	private SimpleBinder simple;
	
	/**
     * 在 Local Service 中我们直接继承 Binder 而不是 IBinder,因为 Binder 实现了 IBinder 接口，这样我们可以少做很多工作。
     * @author newcj
     */
    public class SimpleBinder extends Binder{
        /**
         * 获取 Service 实例
         * @return
         */
        public MyBindService getService(){
            return MyBindService.this;
        }
         
        public int add(int a, int b){
            return a + b;
        }
    }
    
    @Override
    public void onCreate() {
    	// TODO Auto-generated method stub
    	Log.e("IBinder", "------------MyBindService-onCreate");
    	super.onCreate();
    	simple = new SimpleBinder();
    }

	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return simple;
	}
	
	public String getMessage()
	{
		return "连接MyBindService成功";
	}
	
	@SuppressLint("NewApi")
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		// TODO Auto-generated method stub
		Log.e("IBinder", "------------MyBindService-onStartCommand");
		return super.onStartCommand(intent, flags, startId);
	}
	
	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		Log.e("IBinder", "------------MyBindService-onDestroy");
		super.onDestroy();
	}

}
